package com.jk.service.impl;

import com.github.pagehelper.PageHelper;
import com.jk.bean.*;
import com.jk.mapper.GZMapper;
import com.jk.service.GZService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class GZServiceImpl implements GZService {

    @Resource
    private GZMapper  gzMapper;

    @Override
    public SendPage queryGZdu(Page page,String  userid) {

          List<GZDu>  list=gzMapper.queryAllGZdu(userid);

        PageHelper.startPage(page.getPage(),page.getRows());
        List<GZDu>  data=gzMapper.queryAllGZdu(userid);
        SendPage  sp=new  SendPage(list.size(),data);
            return sp;
    }

    @Override
    public List<TuTu> queryLunBoTu() {
        return gzMapper.queryLunBoTu();
    }

    @Override
    public List<TuTu> queryBaoXiao() {
        return gzMapper.queryBaoXiao();
    }

    @Override
    public List<TuTu> queryShenDuYueDu() {
        return gzMapper.queryShenDuYueDu();
    }

    @Override
    public void tuiJian(TuTu tu,String  username) {
           tu.setBzname(username);
        gzMapper.tuiJian(tu);
    }

    @Override
    public List<TuTu> boWenPaiHang() {
        return gzMapper.boWenPaiHang();
    }

    @Override
    public SendPage queryNamePaiXu(Page page) {

        List<Author>   list=gzMapper.queryNamePaiXu();

        PageHelper.startPage(page.getPage(),page.getRows());
        List<Author>   data=gzMapper.queryNamePaiXu();

        SendPage  sp=new  SendPage(list.size(),data);
        return sp;
    }

    @Override
    public String updateGZ(String aid, String sta) {
          if(sta.equals("1")){
              gzMapper.updateGZ(aid,2,"-1");
          }
          if(sta.equals("2")){
              gzMapper.updateGZ(aid,1,"+1");
          }
          return  "";
    }

    @Override
    public SendPage queryUpDown(Page  page) {
        List<Author>  list=gzMapper.queryUpDown();

        PageHelper.startPage(page.getPage(),page.getRows());
        List<Author>  data=gzMapper.queryUpDown();
        SendPage  sp=new  SendPage(list.size(),data);
        return sp;
    }

    //上移  下移
    @Override
    public void upDownAuthor(String aid, Integer sta,Integer  num) {
        int  weizhi=0;  //查询出要上移或下移的  行号rownum 变量
        int  jcid=0;    //查询要交换行的id;
        int  jhxuhao=0;    //交换的排序字段值
          if(sta==0){  //下移
             weizhi=gzMapper.downWeiZhi(aid);
         }

         if(sta==1){ //上移
             weizhi=gzMapper.upWeiZhi(aid);
         }

        jcid=gzMapper.jiaoHuanID(weizhi);
        jhxuhao=gzMapper.jiaoHuanNum(jcid);

        String  jid=jcid+"";
        gzMapper.jiaoHuanOne(aid,jhxuhao);
        gzMapper.jiaoHuanOne(jid,num);
    }

    @Override
    public void zhiDing(Integer aid, int aa) {
        gzMapper.zhiDing(aid,aa);
    }

}
